package com.jdyinfo.ic.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jdyinfo.ic.mysql.entity.User;
import com.jdyinfo.ic.request.eweixin.Department;
import com.jdyinfo.ic.service.UserService;
import com.jdyinfo.ic.service.WorkWeixinService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value="/user",tags="dfds")
@RestController
@EnableAutoConfiguration
@RequestMapping("/")
public class UserController {
	Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	ObjectMapper objectMapper;
	
	@Autowired
	UserService userService;
	
	@Autowired
	WorkWeixinService workWeixinService;
	
	@GetMapping("/xx/1")
	String xxx() {
		return workWeixinService.getUserById("XuDongCai");
	}
	
	@GetMapping("/xx/2")
	String yyy() {
		return workWeixinService.getUserByDepartment("1");
	}
	
	@GetMapping("/department/1")
	String department1() {
		return workWeixinService.getDepartments();
	}
	
	@GetMapping("/department/2")
	String department2() {
		return workWeixinService.getDepartmentById("1");
	}
	
	@PostMapping("/department/create")
	String department2(@RequestBody Department department) throws Exception{
		String json = objectMapper.writeValueAsString(department);
		logger.info(json);
		return workWeixinService.createDepartment(json);
	}
	
	@GetMapping("/department/delete")
	String department3() {
		return workWeixinService.deleteDepartment("2");
	}
	
	@ApiOperation(value="",notes="")
	@GetMapping("/user/{id}")
	User getUser(@PathVariable int id) {
		return userService.findUserById(id);
	}
	
	/*@ApiOperation(value="",notes="")
	@PostMapping("/user/{id}")
	User updateUser(@PathVariable String id, @RequestBody User user) {
		return userService.findUserByXXX(xxx).get(0);
	}*/
}
